<?php
/**
* A validation class
*
* The validation class is used to validate inputfields from login/register form.
*
* @author dmq (master@dmq.se)
*/
class Validation
{
	/**
	* function IsValidUserName()
	* @param string $username is the value that the user enters in the username field
	* @return boolean true | false depending if username match reg.exp
	*/
	public function IsValidUsername( $username )
	{
		return preg_match( "/^[a-z0-9_]{4,20}$/i", $username );
	}

	/**
	* function IsValidPassword()
	* @param string $password is the value that the user enters in the password field
	* @return boolean true | false depending if password match reg.exp
	*/
	public function IsValidPassword( $password )
	{
		return preg_match( "/^\S{6,20}$/i" , $password );
	}

	/**
	* function IsValidEmail()
	* @param string $email is the value that the user enters in the email field
	* @return boolean true/false depending if email match reg.exp
	*/
	public function IsValidEmail( $email )
	{
		return preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/i', $email );
	}

	/**
	* function IsValidMaxPlayers()
	* @param string $maxPlayers is the value that the user choose in maxPlayers dropbox
	* @return boolean true/false depending if maxPlayers match reg.exp
	*/
	public function IsValidMaxPlayers( $maxPlayers ) {
		return preg_match('/^[2-8]$/i', $maxPlayers );
	}
}
